package com.example.business_oa.controller;

import cn.hutool.core.date.DateUtil;
import com.example.business_oa.service.QiDongBuKaService;
import com.example.business_oa.service.RcService;
import com.example.business_oa.service.SelectLeaderService;
import com.example.business_oa.service.ShenPiQingJiaService;
import com.example.comment_oa.pojos.SysEmployee;
import com.example.comment_oa.pojos.attendance.HolidayAp;
import com.example.comment_oa.pojos.attendance.ReplacementCardAp;
import com.example.comment_oa.pojos_vo.flowableVo.taskVo;
import com.example.comment_oa.response.AjaxResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;

@RestController
@CrossOrigin
@RequestMapping("/businessOa/Rc")
public class RcController {
    @Resource
    RcService rcService;

    @Resource
    QiDongBuKaService qiDongBuKaService;

    @Resource
    SelectLeaderService selectLeaderService;

    @Resource
    ShenPiQingJiaService shenPiQingJiaService;

    @PostMapping("ap")
    public AjaxResponse apRc(){
        return AjaxResponse.success();
    }

    @PostMapping("yes")
    public AjaxResponse yesRc(){
        return AjaxResponse.success();
    }

    @PostMapping("no")
    public AjaxResponse noRc(){
        return AjaxResponse.success();
    }

    @PostMapping("/qidongBuKaLiuCheng")
    public AjaxResponse qidongBuKaLiuCheng(ReplacementCardAp replacementCardAp, MultipartFile file){
        int i = rcService.apRc(replacementCardAp,file);
        if(i==3){
            //流程
            String gonghao = replacementCardAp.getUserRc();
            HashMap<String, Object> variables = new HashMap<>();
            SysEmployee sysEmployee = selectLeaderService.selectGongHao(gonghao);

            String assignee1 = sysEmployee.getEmpCard();
            String bianhao = replacementCardAp.getRcWater();
            qiDongBuKaService.qidongBuKaLiuCheng(gonghao,variables,assignee1,bianhao);
        }

        //一个 发起人的工号
            // 一个用来查询的主键
//           qiDongBuKaService.qidongBuKaLiuCheng();

        return AjaxResponse.success(i);
    }



    @PostMapping("/jujuebuka")
    public AjaxResponse jujuebuka(@RequestBody taskVo taskVo){
        System.err.println(taskVo);
        if(taskVo.getApprovd()==false){
            rcService.noRc(taskVo.getBianhao(),taskVo.getLingdao());
        }
        shenPiQingJiaService.QingJiaShenPiJuJue(taskVo);
        return AjaxResponse.success();
    }

    @PostMapping("/tongyibuka")
    public AjaxResponse tongyibuka(@RequestBody taskVo taskVo){
        System.err.println(taskVo);
        int i =0;
        if(taskVo.getApprovd()){
            String s = DateUtil.formatDate(new Date());
            i=rcService.yesRc(s.substring(0, 7), taskVo.getPerson(), taskVo.getBianhao(), taskVo.getLingdao());
        }
        System.err.println("i是什么："+i);
        if(i==1){
            shenPiQingJiaService.QingJiaShenPiTongYi(taskVo);
        }

        return AjaxResponse.success(i);
    }

}
